<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class jQuickForm_Element_FckEditor extends HTML_QuickForm2_Element_Textarea {
    public function render(HTML_QuickForm2_Renderer $renderer){
        /*jQuickForm::js()->addJs('/vendors/fckeditor/fckeditor.js');
//        jQuickForm::js()->addJs('/vendors/fckeditor/fckconfig.js');
        jQuickForm::js()->addJsInline('
// called when FCKeditor is done starting..
function FCKeditor_OnComplete( editorInstance ){
    jQuery("form > submit").click(function(){
        jQuery("#"+editorInstance.Name).val(editorInstance.GetXHTML("html"));
        return jQuery(this).submit();
    });
}
        ');
        jQuickForm::js()->addJsOnload('
var oFCKeditor = new FCKeditor(\''.$this->getId().'\');
oFCKeditor.BasePath = \'/vendors/fckeditor/\';
oFCKeditor.ToolbarSet="Basic";
oFCKeditor.ReplaceTextarea();
        ');*/


		include_once($_SERVER['DOCUMENT_ROOT'].'/data/js/fckeditor/fckeditor_php5.php');

		$text = $this->getValue();
		$id = str_replace("-", "_", $this->getId());
		$sBasePath = '/data/js/fckeditor/';

		//$oFCKeditor = new FCKeditor('FCKeditor_'.$id) ;

		//$oFCKeditor->BasePath	= $sBasePath ;
		//$oFCKeditor->Value		= ($text!=""?$text:"<p>&nbsp;</p>");
		//$oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/default/' ;
//		if (substr_count($this->getId(), 0) == 0) {
//			$oFCKeditor->Config['StartupFocus'] = false;
//		}
//		$oFCKeditor->Height = 300;
		//$html = $oFCKeditor->CreateHtml();


        $renderer->setTemplateForClass(strtolower(get_class($this)),'<div class="jqf_row havefckeditor">
    <label for="{id}" class="jqf_element"><qf:required><span class="required">* </span></qf:required>{label}</label>
	{comment}{element}

<div class="clear"></div>
</div>');

		$h = $this->getHeight();
		$height = ($h != null?$h:500);

		jQuickForm::js()->addJsFCK("
			var oFCKeditor = new FCKeditor('".$this->getId()."');
				oFCKeditor.BasePath = '".$sBasePath."';
				oFCKeditor.Height = ".$height.";
				".(substr_count($this->getId(), 0) == 0?"oFCKeditor.Config['StartupFocus'] = false;":"")."
				oFCKeditor.ReplaceTextarea();
		");


        return parent::render($renderer);
    }
}
?>